package lock_250417;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class lock1 {

    public static void main(String[] args) {
        ReentrantLock lock1 = new ReentrantLock();
        Run1 run1 = new Run1(lock1);
        new Thread(run1,"线程1").start();
        new Thread(run1,"线程2").start();
    }

}

class Run1 implements Runnable {
    private ReentrantLock lock;
    public Run1(ReentrantLock lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            lock.lock();
            TimeUnit.SECONDS.sleep(2);
            System.out.println(Thread.currentThread().getName()+" run");
            lock.unlock();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }


    }
}
